package com.mcflies.aotoPartsManager.util;

import java.util.Properties;

import org.apache.log4j.Logger;

import com.mcflies.aotoPartsManager.service.AutoPartsBaseService;
import com.mcflies.aotoPartsManager.service.CustomerAreaService;

/**
 * 
 * AutoPartsServiceFactory.java
 * 
 * @describe：汽车配件管理系统Service工厂类
 * @Copyright(c) 2012-2024 Study,mcfly
 * @author mcfly_jun
 */
public class AutoPartsServiceFactory {
	private static AutoPartsBaseService autoPartsBaseService;
	private static CustomerAreaService customerAreaService;

	private static Logger log = Logger.getLogger(AutoPartsServiceFactory.class);
	private static Properties pro;
	static {
		try {
			pro = new Properties();
			pro.load(AutoPartsServiceFactory.class.getClassLoader().getResourceAsStream(
					"com/mcflies/aotoPartsManager/util/autoPartsServiceConfig.properties"));

		} catch (Exception e) {
			log.info("在[" + AutoPartsServiceFactory.class.getName() + "]中加载(static代码块)出现：：" + e.getMessage() + "异常");
		}
	}

	/**
	 * 实例化AutoPartsBaseService
	 * 
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public synchronized static AutoPartsBaseService initAutoPartsBaseService() throws Exception {
		if (null == autoPartsBaseService) {
			Class cls = Class.forName(pro.getProperty(AutoPartsConstantKey.AUTO_PARTS_BASE_SERVICE));
			autoPartsBaseService = (AutoPartsBaseService) cls.newInstance();
		}
		return autoPartsBaseService;
	}

	/**
	 * 实例化CustomerAreaService
	 * 
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public synchronized static CustomerAreaService initCustomerAreaService() throws Exception {
		if (null == customerAreaService) {
			Class cls = Class.forName(pro.getProperty(AutoPartsConstantKey.AUTO_PARTS_CUSTOMER_AREA_SERVICE));
			customerAreaService = (CustomerAreaService) cls.newInstance();
		}
		return customerAreaService;
	}
}
